package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallBrandCategoryMapper;
import org.linlinjava.litemall.db.dao.LitemallCategoryMapper;
import org.linlinjava.litemall.db.domain.LitemallBrandCategory;
import org.linlinjava.litemall.db.domain.LitemallBrandCategoryExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LitemallBrandCategoryService {
    @Resource
    private LitemallBrandCategoryMapper brandCategoryMapper;
    @Resource
    private LitemallCategoryMapper categoryMapper;


    /**
     * @Description  查询公司拥有检测种类的情况，或者查询可以检测某个种类的公司 2020.05.14后categoryId 指代 L3级别
     * @Author Riko
     * @Date 2019/9/20
     **/
    public List<LitemallBrandCategory> getAllBrandAndCategory(Integer brandId, Integer categoryId, Integer page, Integer limit) {
        LitemallBrandCategoryExample example = new LitemallBrandCategoryExample();
        LitemallBrandCategoryExample.Criteria criteria = example.createCriteria();
        if (brandId != null) {
            criteria.andBrandIdEqualTo(brandId);
        }
        if (categoryId != null) {
            criteria.andCategoryIdEqualTo(categoryId);
        }
        PageHelper.startPage(page, limit);
        return brandCategoryMapper.selectByExample(example);
    }

    /**
     * @Description  新增公司可以进行检测的项目
     * @Author Riko
     * @Date 2019/9/20
     **/
    public void addCategoryForBrand(Integer brandId, List<Integer> categoryIdList) {
        brandCategoryMapper.insertList(brandId, categoryIdList);
    }

    /**
     * @Description  删除公司可以进行检测的项目
     * @Author Riko
     * @Date 2019/9/20
     **/
    public void deleteCategoryForBrand(Integer brandId, List<Integer> categoryIdList) {
        LitemallBrandCategoryExample example = new LitemallBrandCategoryExample();
        example.or().andCategoryIdIn(categoryIdList).andBrandIdEqualTo(brandId);
        brandCategoryMapper.deleteByExample(example);
    }

    public void update(LitemallBrandCategory litemallBrandCategory) {
        brandCategoryMapper.updateByPrimaryKeySelective(litemallBrandCategory);
    }

    public void addBrandCategory(LitemallBrandCategory brandCategory) {
        brandCategoryMapper.insertSelective(brandCategory);
    }



}
